package com.example.noteapp.HomePager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.example.noteapp.R;
import com.example.noteapp.databinding.ActivityHomeBinding;
// 注意：这里 ActivityLoginBinding 可能不对，应该是 ActivityHomeBinding，
// 假设你实际是 HomeActivity 对应布局是 activity_home.xml，需确认 Binding 类名

public class HomeActivity extends AppCompatActivity {
    ActivityHomeBinding binding;
    NoteFragment noteFragment;
    PicFragment picFragment;
    ProfileFragment profileFragment;
    Fragment current;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityHomeBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        initMethod();

    }

    private void initMethod(){
        noteFragment = new NoteFragment();
        profileFragment = new ProfileFragment();
        picFragment = new PicFragment();
        changeFragment(noteFragment);
        binding.bottomNavigation.setOnItemSelectedListener(item -> {
            switch (item.getItemId()) {
                case R.id.menu_note:
                    changeFragment(noteFragment);
                    break;
                case R.id.menu_pic:
                    changeFragment(picFragment);
                    break;
                case R.id.menu_profile:
                    changeFragment(profileFragment);
                    break;
            }
            item.setChecked(true);
            return true;
        });

    }
    public void changeFragment(Fragment to) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(binding.navFragment.getId(), to);
        fragmentTransaction.commit();
        current = to;
    }

}